home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / rk_plot.zip / ALPHA-.ASM < prev    next >
Assembly Source File  |  1991-05-13  |  7KB  |  252 lines

  1. ;***********************************************************************
  2. ; ALPHA-.ASM    Version ohne Bereichsprüfung bei AlphaPunktSetzen
  3. ; Copyright     (C) 1991, Hans-Jürgen Herrler und Dieter Sosna
  4. ;***********************************************************************
  5.                 
  6. DATA    SEGMENT BYTE PUBLIC
  7.  
  8.         ; Pascal Variable
  9.         EXTRN   AlphaMax                : word
  10.         EXTRN   AlphaMin                : word
  11.         EXTRN   maxTemp                 : word
  12.         EXTRN   minTemp                 : word
  13.         EXTRN   AlphaColor              : Byte;
  14.  
  15.         ; Pascal Prozedur (Unit Graph)
  16.         EXTRN   PutPixel                : far
  17.         EXTRN   GetMaxX                 : far
  18.         EXTRN   GetMaxY                 : far
  19.  
  20. DATA    ENDS
  21.  
  22. CODE    SEGMENT BYTE PUBLIC
  23.         ASSUME CS:CODE, DS:DATA
  24.  
  25.         PUBLIC  AlphaLine
  26.         PUBLIC  InitAlphaPuffer
  27.         PUBLIC  AlphaPufferAktualisieren
  28.  
  29. AlphaPunktSetzen PROC NEAR
  30.  
  31.         ; Input: ax = X, bx = Y
  32.         ; --> Punkt wird gesetzt in der Farbe AlphaColor
  33.  
  34.         push    ax
  35.         push    bx
  36.         push    cx
  37.         push    dx
  38.         push    bp
  39.  
  40.         xor     dx,dx                   ; Boolean-Flag "Setzen" := False
  41.         mov     di,ax
  42.         shl     di,1                    ; di := 2 * X
  43.  
  44.         cmp     bx,[di+Offset AlphaMax] ; Y > AlphaMax[X] ?
  45.         jle     APS1
  46.  
  47.         inc     dx                      ; Setzen := True
  48.         cmp     bx,[di+Offset maxTemp]  ; Y > maxTemp[X] ?
  49.         jle     APS1
  50.         mov     [di+Offset maxTemp],bx  ; maxTemp[X] := Y
  51.  
  52. APS1:   cmp     bx,[di+Offset AlphaMin] ; Y < AlphaMin[X] ?
  53.         jnl     APS2
  54.         inc     dx                      ; Setzen := True
  55.         cmp     bx,[di+Offset minTemp]  ; Y < minTemp[X] ?
  56.         jnl     APS2
  57.         mov     [di+Offset minTemp],bx  ; minTemp[X] := Y
  58.  
  59. APS2:   cmp     dx,00                   ; Setzen = False ?
  60.         je      APS3
  61.         push    ax                      ; Parameter übergeben: x, y, Farbe
  62.         push    bx
  63.         xor     ax,ax
  64.         mov     al,[AlphaColor]
  65.         push    ax
  66.         call    PUTPIXEL                ; Unit Graph
  67.  
  68. APS3:   pop     bp
  69.         pop     dx
  70.         pop     cx
  71.         pop     bx
  72.         pop     ax
  73.         ret
  74.  
  75. AlphaPunktSetzen ENDP
  76.  
  77. Betrag          PROC    NEAR
  78.         ; Input:        cx = Integer1   dx = Integer2
  79.         ; Output:       cx = Absoluter Betrag(Integer1 - Integer2)
  80.         ;               dx = 1, falls Integer2 >= Integer1, sonst dx = -1
  81.  
  82.         add     cx,8000h
  83.         add     dx,8000h
  84.         cmp     dx,cx
  85.         jc      Betr1
  86.  
  87.         ; falls Integer2 >= Integer1
  88.         push    cx
  89.         mov     cx,dx
  90.         pop     dx
  91.         sub     cx,dx
  92.         mov     dx,0001h
  93.         jmp     Betr2
  94.  
  95.         ; falls Integer2 < Integer1
  96. Betr1:  sub     cx,dx
  97.         mov     dx,0FFFFh
  98.  
  99. Betr2:  ret
  100.  
  101. Betrag          ENDP
  102.  
  103. AlphaLine       PROC    FAR
  104.  
  105.         ; Parameter auf dem Stack
  106. P2X     EQU     6
  107. P2Y     EQU     P2X + 2
  108. P1X     EQU     P2Y + 2
  109. P1Y     EQU     P1X + 2
  110.         ; lokale Variablen
  111. XStep   EQU     -2
  112. YStep   EQU     XStep - 2
  113. DeltaX  EQU     YStep - 2
  114. DeltaY  EQU     DeltaX - 2
  115.  
  116.         push    bp
  117.         mov     bp,sp
  118.         sub     sp,0008h                ; Platz für lokale Variablen
  119.  
  120.         ; DeltaX := Abs(LongInt(P1X)-LongInt(P2X))
  121.  
  122.         mov     cx,[bp+P1X]
  123.         mov     ax,cx                   ; ax = X
  124.         mov     dx,[bp+P2X]
  125.         call    Betrag
  126.         mov     [bp+DeltaX],cx
  127.         mov     [bp+XStep],dx
  128.  
  129.         ; DeltaY := Abs(LongInt(P1Y)-LongInt(P2Y))
  130.         mov     cx,[bp+P1Y]
  131.         mov     bx,cx                   ; bx = Y
  132.         mov     dx,[bp+P2Y]
  133.         call    Betrag
  134.         mov     [bp+DeltaY],cx
  135.         mov     [bp+YStep],dx
  136.  
  137.         ; IF DeltaX >= DeltaY THEN Flach := True ELSE Flach := False
  138.         push    ax
  139.         mov     ax,[bp+DeltaX]
  140.         cmp     ax,[bp+DeltaY]
  141.         pop     ax
  142.         jc      Steil
  143.  
  144.         ; Flach: Hier ist X die unabhängige Variable
  145.         mov     dx,[bp+DeltaX]
  146.         mov     cx,dx                   ; cx = Schleifenzähler
  147.         shr     dx,1                    ; dx = Control = DeltaX / 2
  148.         call    AlphaPunktSetzen
  149.  
  150. Loop1:  add     ax,[bp+XStep]           ; Inc(X, XStep)
  151.         sub     dx,[bp+DeltaY]          ; Dec(Control, DeltaY)
  152.         jg      ALine1
  153.  
  154.         ; Falls Control <= 0:
  155.         add     bx,[bp+YStep]           ; Inc(Y, YStep)
  156.         add     dx,[bp+DeltaX]          ; Inc(Control, DeltaX)
  157.  
  158. ALine1: call    AlphaPunktSetzen
  159.         loop    Loop1
  160.         jmp     ALine3
  161.  
  162. Steil:  mov     dx,[bp+DeltaY]
  163.         mov     cx,dx                   ; cx = Schleifenzähler
  164.         shr     dx,1                    ; dx = Control = DeltaY / 2
  165.         call    AlphaPunktSetzen
  166.  
  167. Loop2:  add     bx,[bp+YStep]           ; Inc(Y, YStep)
  168.         sub     dx,[bp+DeltaX]          ; Dec(Control, DeltaX)
  169.         jg      ALine2
  170.  
  171.         ; Falls Control <= 0:
  172.         add     ax,[bp+XStep]           ; Inc(X, XStep)
  173.         add     dx,[bp+DeltaY]          ; Inc(Control, DeltaY)
  174.  
  175. ALine2: call    AlphaPunktSetzen
  176.         loop    Loop2
  177.  
  178. ALine3: mov     sp,bp
  179.         pop     bp
  180.         ret     0008h
  181.  
  182. AlphaLine       ENDP
  183.  
  184. InitAlphaPuffer PROC FAR
  185.  
  186.         cld                             ; Richtung: aufsteigend
  187.         push    ds
  188.         pop     es
  189.         call    GetMaxX
  190.         inc     ax
  191.         push    ax
  192.  
  193.         mov     cx,ax
  194.         mov     ax,0FFFFh
  195.         mov     di,Offset AlphaMax
  196.         rep
  197.         stosw
  198.  
  199.         call    GetMaxY
  200.         inc     ax
  201.         mov     di,Offset AlphaMin
  202.         pop     cx
  203.         push    cx
  204.         rep
  205.         stosw
  206.  
  207.         mov     si,Offset AlphaMax
  208.         mov     di,Offset maxTemp
  209.         pop     cx
  210.         push    cx
  211.         rep
  212.         movsw
  213.  
  214.         mov     si,Offset AlphaMin
  215.         mov     di,Offset minTemp
  216.         pop     cx
  217.         rep
  218.         movsw
  219.  
  220.         ret
  221.  
  222. InitAlphaPuffer ENDP
  223.  
  224. AlphaPufferAktualisieren        PROC FAR
  225.  
  226.         cld                             ; Richtung: aufsteigend
  227.         push    ds
  228.         pop     es
  229.         call    GetMaxX
  230.         inc     ax
  231.         push    ax
  232.  
  233.         mov     si,Offset maxTemp
  234.         mov     di,Offset AlphaMax
  235.         pop     cx
  236.         push    cx
  237.         rep
  238.         movsw
  239.  
  240.         mov     si,Offset minTemp
  241.         mov     di,Offset AlphaMin
  242.         pop     cx
  243.         rep
  244.         movsw
  245.  
  246.         ret
  247.  
  248. AlphaPufferAktualisieren        ENDP
  249.  
  250.         ENDS
  251.         END
  252.